home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
drdobbs
/
1991
/
01
/
gui.asc
< prev
next >
Wrap
Text File
|
1990-12-07
|
3KB
|
119 lines
_DESIGNING A PORTABLE GUI TOOLKIT_
by Robert T. Nicholson
[LISTING ONE]
/* make_my_window -- Application code to create a window demonstrates use of
attributes for overspecification. The programmer can specify values for
window properties applying to any underlying GUI, or can accept
platform-specific defaults. Routines and constants prefaced with the
letters "ui" are toolkit routines.
*/
uiWindow make_my_window(private_data)
ptr_t private_data;
{
struct
uiWindowAttr window_attr; /* window attributes */
uiWindow the_window; /* The window created */
/* Set the attibute "mask" for the attributes we're concerned with */
window_attr.mask = uiWINDOW_A_EVENT |
uiWINDOW_A_TYPE |
uiWINDOW_A_MODALITY |
uiWINDOW_A_POSITION |
uiWINDOW_A_SIZE |
uiWINDOW_A_TITLE |
uiWINDOW_A_CANRESIZE |
uiWINDOW_A_CANCLOSE |
uiWINDOW_A_CANMINIMIZE |
uiWINDOW_A_CANMAXIMIZE |
uiWINDOW_A_CANTITLE |
uiWINDOW_A_VSATYPE |
uiWINDOW_A_HSATYPE;
/* Set the desired attribute values */
/* EVENT - register the event handler, and a pointer to an application data
structure that will be passed to the event routine when it is called. */
window_attr.eventproc = my_event_routine;
window_attr.eventarg = private_data;
/* TYPE & MODALITY - a non-modal document window */
window_attr.type = uiWINDOW_DOCUMENT;
window_attr.modality = uiWINDOW_MODALITY_NONE;
/* POSITION, SIZE, and TITLE */
window_attr.x = 200;
window_attr.y = 100;
window_attr.width = 500;
window_attr.height = 300;
window_attr.title = "Untitled";
/* CANRESIZE, CANCLOSE, CANMINIMIZE, CANMAXIMIZE, CANTITLE - these permissions
determine how the user can manipulate this window. We could simply accept
platform-specific defaults for these, to maintain local look and feel. */
window_attr.canresize = TRUE;
window_attr.canclose = TRUE;
window_attr.canminimize = TRUE;
window_attr.canmaximize = TRUE;
window_attr.cantitle = TRUE;
/* VSATYPE & HSATYPE - window will have vertical and horizontal scrollbars */
window_attr.vsatype = uiWINDOW_SATYPE_BAR;
window_attr.hsatype = uiWINDOW_SATYPE_BAR;
the_window = uiWindowCreate(&window_attr);
return the_window;
}
[LISTING TWO]
/* button_routine -- A sample of an event handler routine that processes
events for three buttons in a dialog box. Data structures prefaced with
the letters "ui" are toolkit structures.
*/
void button_routine(the_event, private_data)
uiEvent *the_event; /* Event record pointer */
ptr_t private_data; /* Dialog's data pointer */
{
switch (the_event->type)
{
/* Handle button-push events for all three of the
dialog's buttons. */
case uiEVENT_PUSHB:
if (the_event->recipient ==
((dialog_data_struct *) private_data)->yes_button)
do_yes_action(private_data);
if (the_event->recipient ==
((dialog_data_struct *) private_data)->no_button)
do_no_action(private_data);
if (the_event->recipient ==
((dialog_data_struct *) private_data)->cancel_button)
do_cancel_action(private_data);
break;
/* Handle key events - if the user pressed the Return
key, treat it the same as the "Yes" button, which
is the default button for this dialog. */
case uiEVENT_KEY:
if (((uiEventKey *) the_event)->key) == '\n')
do_yes_action(private_data);
else
uiWSBeep();
/* (Not interested in any other events that the buttons
may receive.) */
}
return;
}